package com.origin.niuke.tree;

import general_class.TreeNode;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/7/27 22:24
 * 判断是不是二叉搜索树
 * 算法：中序遍历
 */
public class BM34 {

    int preVal = Integer.MIN_VALUE;
    public boolean isValidBST (TreeNode root) {
        if (root == null) return true;
        if (!isValidBST(root.left)) return false;
        if (preVal >= root.val) return false;
        preVal = root.val;
        return isValidBST(root.right);
    }

}
